window.onload = function () {
    getAllDormitory();
}

var layer, table;
layui.use(['layer', 'laydate', 'table'], function () {
    $ = layui.jquery;
    var layer = layui.layer,
        laydate = layui.laydate,
        table = layui.table;

    // 初始化表格
    table.render({
        //设置ID
        id: 'visitRecordTable',
        // 指定原始 table 容器
        elem: '#tempRecordTableId',
        // 异步数据接口
        url: '/temp/findVisitRecord',
        where: {stuName: '', dormitoryId: ''},
        // 设置导出按钮
        toolbar: true,
        //设置表头。值是一个二维数组
        cols: [
            [{
                type: 'numbers',
                width: 50,
                title: '序号',
                fixed: "left"
            }, {
                field: 'stuId',
                minWidth: 100,
                title: '学号',
                align: "center"
            }, {
                field: 'stuName',
                minWidth: 100,
                title: '学生姓名',
                align: "center"
            }, {
                field: 'deptName',
                minWidth: 150,
                title: '院系',
                align: "center"
            }, {
                field: 'majorName',
                minWidth: 150,
                title: '专业',
                align: "center"
            }, {
                field: 'clazzName',
                minWidth: 150,
                title: '班级',
                align: "center"
            }, {
                field: 'dormitoryName',
                minWidth: 150,
                title: '访问宿舍',
                align: "center"
            }, {
                field: 'stuTemp',
                minWidth: 80,
                title: '体温',
                align: "center"
            }, {
                field: 'recordDate',
                minWidth: 180,
                title: '登记时间',
                align: "center"
            }]
        ],
        // 每页条数的选择项
        limits: [5, 10, 15, 20, 25, 50, 100],
        // 每页显示的条数
        limit: 15,
        // 是否开启分页
        page: true
    });

    // 查询按钮
    $('#searchBtn').on('click', function () {
        //执行搜索重载
        table.reload('visitRecordTable', {
            page: {
                curr: 1
            },
            where: {
                stuName: $("#stuName").val(),
                dormitoryId: $("#dormitory").val()
            }
        }, 'data');
    });
});

/**
 * 获取所有宿舍
 * @param dormitoryId
 */
function getAllDormitory(dormitoryId) {
    param = {
        dormitoryId: ""
    }
    $.ajax({
        type: "POST",
        url: "/dormitory/getAllDormitory",
        // contentType: "application/json",
        sync: true,
        data: param,
        dataType: "json",
        success: function (result) {
            $("#dormitory").empty();
            $("#dormitory").append("<option value=''>请选择宿舍</option>");
            if (result.code == 200) {
                $.each(result.data, function (i, o) {
                    var opt = '';
                    if (dormitoryId === o.dormitoryId) {
                        opt = '<option value=' + o.dormitoryId + ' selected>' + o.dormitoryName + '</option>';
                    } else {
                        opt = '<option value=' + o.dormitoryId + '>' + o.dormitoryName + '</option>';
                    }
                    $("#dormitory").append(opt);
                });
            }
            $("#dormitory").selectpicker('refresh');//动态加载
        }
    });
}

